package com.fyb.basic.juc.countDownLatch;

import java.util.concurrent.CountDownLatch;

/**
 * @Author：MR.FANG
 * @name：demo
 * CountDownLatch: 计数器为0 才继续向下执行
 * 问题：大门关闭的前提是  需要6辆客车全部离开
 * @Date：2025/7/2 下午3:51
 */
public class demo {

    private static CountDownLatch countDownLatch = new CountDownLatch(5);

    public static void main(String[] args) throws InterruptedException {

        for (int i = 0; i < 5; i++) {
            final int temp = i + 1;
            new Thread(() -> {
                System.out.println(Thread.currentThread().getName() + "第" + temp + "辆，客车离开 \t");
                countDownLatch.countDown();
            }, "t"+temp + "").start();
        }
        countDownLatch.await();
        System.out.println(Thread.currentThread().getName() + "\t 大门已经关闭");
    }
}
